home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.5 KB | 393 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLnkSrc.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWLNKCMD_H
- #include "FWLnkCmd.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odflinking
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CLinkSource)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CLinkSource)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CLinkSource>
- #pragma template FW_TOrderedCollectionIterator<FW_CLinkSource>
-
- #endif
-
- //========================================================================================
- // class FW_CLinkSource
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::FW_CLinkSource
- //---------------------------------------------------------------------------------------
-
- FW_CLinkSource::FW_CLinkSource(Environment* ev,
- ODUpdateID updateID,
- FW_CPresentation* presentation)
- : FW_CLink(ev, presentation),
- fODLinkSource(NULL),
- fUpdateID(updateID),
- fPendingID(updateID),
- fDataInterchange(presentation->GetPart(ev)->GetDataInterchange(ev)),
- fLinkPromise(NULL),
- fPendingCommand(NULL)
- {
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::~FW_CLinkSource
- //---------------------------------------------------------------------------------------
-
- FW_CLinkSource::~FW_CLinkSource()
- {
- if (fODLinkSource)
- {
- FW_SOMEnvironment ev;
- fODLinkSource->Release(ev);
- }
-
- if (fLinkPromise)
- delete fLinkPromise;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::SetODLinkSource
- //---------------------------------------------------------------------------------------
-
- void FW_CLinkSource::SetODLinkSource(Environment* ev, ODLinkSource* odLinkSource)
- {
- FW_ASSERT(odLinkSource!=NULL);
- FW_ASSERT(fODLinkSource==NULL);
-
- fODLinkSource = odLinkSource;
- odLinkSource->Acquire(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::PrivSetPromise
- //---------------------------------------------------------------------------------------
-
-
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ContentUpdated
- //---------------------------------------------------------------------------------------
-
- void FW_CLinkSource::ContentUpdated(Environment* ev, ODUpdateID updateID,
- FW_Boolean forceUpdate)
- {
- FW_Boolean justRewrite = (updateID == kODUnknownUpdate) && forceUpdate;
- ODUpdateID newID = updateID ? updateID : justRewrite ? fUpdateID : FW_CSession::UniqueUpdateID(ev);
-
- // Don't update unless we really have to
- if (this->IsOKtoUpdate(ev, forceUpdate))
- {
- ODLinkKey key;
- FW_VOLATILE(key);
-
- if (fODLinkSource->Lock(ev, 0, &key))
- {
-
- FW_TRY
- {
- fODLinkSource->Clear(ev, newID, key);
- // Clear must be followed by GetContentStorageUnit, which writes out a new set of promises
- ODStorageUnit* linkSU = fODLinkSource->GetContentStorageUnit(ev, key);
-
- ExternalizeLinkContent(ev, linkSU);
-
- if (!justRewrite)
- fODLinkSource->ContentUpdated(ev, newID, key);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- fODLinkSource->Clear(ev, fUpdateID, key);
- fODLinkSource->Unlock(ev, key);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- fODLinkSource->Unlock(ev, key);
- }
- }
-
- fUpdateID = newID;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ResolveAllPromises
- //----------------------------------------------------------------------------------------
- // [HLX] Might not be completely right ????
-
-
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::HasEmbeddedFrame
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_CLinkSource::HasEmbeddedFrame(Environment* ev, ODFrame* odEmbeddedFrame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odEmbeddedFrame);
-
- // Should be overridden if the part supports embedding.
- // Return TRUE if odEmbeddedFrame is involved in this link source.
-
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::IsOKtoUpdate
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_CLinkSource::IsOKtoUpdate(Environment* ev, FW_Boolean forceUpdate)
- {
- return (forceUpdate || fODLinkSource->IsAutoUpdate(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::BreakLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::BreakLink(Environment* ev)
- {
- fODLinkSource->SetSourcePart(ev, (ODStorageUnit*) kODNULL);
- fUpdateID = kODUnknownUpdate;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::RestoreLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::RestoreLink(Environment* ev, FW_CPart* part)
- {
- fODLinkSource->SetSourcePart(ev, part->GetStorageUnit(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ExternalizeLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::ExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //-- Storage unit must be focused to property kODPropContents, value linkSourceFormat
- ODStorageUnitRef suRef;
- fODLinkSource->Externalize(ev);
-
- ODID linkID = fODLinkSource->GetID(ev);
- if (cloneInfo != NULL)
- {
- linkID = cloneInfo->Clone(ev, linkID, 0, 0);
- // May not have been able to clone the link
- if (!cloneInfo->GetFromDraft(ev)->IsValidID(ev, linkID))
- return;
- }
-
- //--- Write the link version number ---
- long version = FW_kLinkVersionNumber;
- FW_CByteArray byteArray(&version, sizeof(long));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write a reference to the link ---
- storageUnit->GetStrongStorageUnitRef(ev, linkID, suRef);
- byteArray.Set(&suRef, sizeof(ODStorageUnitRef));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write the update ID ---
- byteArray.Set(&fUpdateID, sizeof(ODUpdateID));
- storageUnit->SetValue(ev, byteArray);
-
- //-- Write out data specific to this part's link --
- this->DoExternalizeLink(ev, storageUnit, cloneInfo);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::PrivLinkEstablished
- //---------------------------------------------------------------------------------------
- void FW_CLinkSource::PrivLinkEstablished(Environment* ev)
- {
- FW_ASSERT(fODLinkSource != NULL);
- FW_CPart* part = fPresentation->GetPart(ev);
- fODLinkSource->SetSourcePart(ev, part->GetODPart(ev)->GetStorageUnit(ev));
-
- //---- Change the link status of affected embedded frames (part-specific)
- this->LinkEstablished(ev);
-
- //--- Force the first update using a new change ID
- ODUpdateID change = FW_CSession::UniqueUpdateID(ev);
- this->ContentUpdated(ev, change, TRUE);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::GetFrameToRevealLink
- //---------------------------------------------------------------------------------------
- FW_CFrame* FW_CLinkSource::GetFrameToRevealLink(Environment* ev)
- {
- // Return a display frame suitable for showing this link.
- // Override to return a frame different from the default (the first one).
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- return piter.First(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::RevealLinkSource
- //---------------------------------------------------------------------------------------
- void FW_CLinkSource::RevealLinkSource(Environment* ev, FW_CFrame* frame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(frame);
- // Override to select the content in this link source
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ShowLinkInfo
- //---------------------------------------------------------------------------------------
- void FW_CLinkSource::ShowLinkInfo(Environment* ev, FW_CFrame* frame, FW_CLinkManager* linkMgr)
- {
- ODLinkInfoResult infoResult;
-
- if (fODLinkSource->ShowLinkSourceInfo(ev, frame->GetActiveFacet(ev), fUpdateID, true, &infoResult))
- {
- switch (infoResult.action)
- {
- case kODLinkInfoBreakLink:
- {
- // Create and execute an undoable command to break the link
- FW_CBreakLinkSourceCommand* cmd = FW_NEW(FW_CBreakLinkSourceCommand, (ev, frame, this, linkMgr));
- cmd->Execute(ev);
- }
- break;
-
- case kODLinkInfoUpdateNow:
- this->ContentUpdated(ev, FW_CSession::UniqueUpdateID(ev), true);
- break;
-
- case kODLinkInfoOk:
- if (infoResult.autoUpdate != fODLinkSource->IsAutoUpdate(ev))
- {
- fODLinkSource->SetAutoUpdate(ev, infoResult.autoUpdate);
- if (infoResult.autoUpdate)
- if (fUpdateID != fODLinkSource->GetUpdateID(ev))
- {
- // changed from manual to automatic updates, and
- // the link is out of date-- update it now
- this->ContentUpdated(ev, FW_CSession::UniqueUpdateID(ev), true);
- }
- }
- break;
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::SetLinkPromise
- //---------------------------------------------------------------------------------------
- void FW_CLinkSource::SetLinkPromise(Environment* ev, FW_CPromise* promise)
- {
- FW_UNUSED(ev);
-
- // Implementations can override this, if for example, they want to just keep reusing
- // the same promise instead of creating a new one each time the link updates.
-
- FW_ASSERT(!promise || promise->PrivGetLinkSource(ev) == this);
-
- if (fLinkPromise != promise)
- {
- if (fLinkPromise)
- delete fLinkPromise;
-
- fLinkPromise = promise;
- }
- }
-
-
-
-
-
-